Skip to content

FRLG add selection arrow detection and start menu navigation#1129

Open
Dalton-V wants to merge 11 commits intoPokemonAutomation:mainfrom
Dalton-V:frlg-add-saving
Open

FRLG add selection arrow detection and start menu navigation#1129
Dalton-V wants to merge 11 commits intoPokemonAutomation:mainfrom
Dalton-V:frlg-add-saving

Conversation

@Dalton-V
Copy link
Contributor

Selection arrow detection and saving tested on Switch1 and Switch2 with different capture cards.

items.add(m_color, m_arrow_box);
}
bool SelectionArrowDetector::detect(const ImageViewRGB32& screen){
double screen_rel_size = (screen.height() / 1080.0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need use GameSettings::instance().GAME_BOX. Take a look at the other FRLG programs. (https://github.com/PokemonAutomation/Arduino-Source/blob/main/SerialPrograms/Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.cpp#L40)

GAME_BOX gives the location of the actual game screen within the entire screen. Then you want all the FRLG inference boxes to be relative to the game box instead of the entire screen.

The idea is that if the game box moves, we only change one setting and everything will work again.

If you want to convert your existing boxes (which are relative to the entire screen) to being relative to the game box, apply this operation:
(x - {0.09375, 0.00462963, 0, 0})/{0.8125, 0.962963, 0.8125, 0.962963}

So taking your first example:

x = {0.685, 0.055, 0.03, 0.075}
(x - {0.09375, 0.00462963, 0, 0})/{0.8125, 0.962963, 0.8125, 0.962963} =
{0.727692, 0.0523077, 0.0369231, 0.0778846}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, to derive box coordinates relative to the game box, Box Draw supports that now.

Set the "Content Box" to {0.8125, 0.962963, 0.8125, 0.962963} (which is the current coordinates of the FRLG game box). Then when you draw the box, it will give you coordinates relative to that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I followed for the most part. Updated and ran a quick test that the save function still works.

I don't think I follow the need to change the 3rd and 4th parameters for the image box as these are height and width. If we are just moving the boxes if the game box moves, shouldn't the size of these boxes stay the same?

size_t min_area = size_t(screen_rel_size_2 * min_area_1080p);

const std::vector<std::pair<uint32_t, uint32_t>> FILTERS = {
{0xff464646, 0xff787878}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet we'll need more filters later. But we'll add them when we need to.

namespace PokemonFRLG {

bool move_cursor_to_position(ConsoleHandle& console, ProControllerContext& context, SelectionArrowPositionStartMenu destination){
SelectionArrowWatcher pokedex_arrow = SelectionArrowWatcher(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works and I'll merge. But in the future, there's a simpler way to do this is to waterfill the entire range of arrows. If the arrow is found, it will come with its coordinates. Then you can calculate which slot it actually is in. So it's a lot cleaner than building N different watchers - one for each possible location.

bool seen_start_menu = false;

WallClock start = current_time();
while (true){
Copy link
Collaborator

@Mysticial Mysticial Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than using a bunch of seen flags, I'd do it this way:

while (true){
    if (too many attempts){
        // throw exception
    }

    //  mash B to back out to overworld.

    //  Press X and wait for start menu to show up
    if (start menu fails to show up){
        print error
        continue;
    }

    //  press + and wait for save dialog
    if (save dialog doesn't show up){
        print error
        continue;
    }

    //  repeat for every step...
}

Basically the moment anything unexpected happens, back out and try again. Don't bother with success flags that you need to jump over and such.

Copy link
Contributor Author

@Dalton-V Dalton-V Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seen flag removed. I left in the save_confirmed flag as that loop needs to happen twice on any game that has a preexisting save.

All flags removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants